package com.jinzhi.jzweb.service.impl;

import com.jinzhi.jzweb.pojo.bo.PublicAndPrivateExpesetotalBo;
import com.jinzhi.jzweb.pojo.bo.PublicRefundListBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jinzhi.jzweb.dao.PublicRefundDao;
import com.jinzhi.jzweb.domain.PublicRefundDO;
import com.jinzhi.jzweb.service.PublicRefundService;
import com.jinzhi.common.base.CoreServiceImpl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2022-03-21 14:07:25 | lance</small>
 */
@Service
public class PublicRefundServiceImpl extends CoreServiceImpl<PublicRefundDao, PublicRefundDO> implements PublicRefundService {

    @Autowired
    private PublicRefundDao publicRefundDao;

    @Override
    public List<PublicRefundDO> listPublicRefund(Map map) {
        if(map.get("pageNumber")!=null){
            if(map.get("pageNumber").toString().equals("1")){
                map.put("pageNumber",0);
            }else {
                Integer number=(Integer) map.get("pageNumber")-1;
                Integer pageSize=(Integer) map.get("pageSize");
                Integer num=number * pageSize;
                map.put("pageNumber",num);
            }
        }
        return publicRefundDao.listPublicRefund(map);
    }

    //查询总数
    @Override
    public Integer listPublicRefundCount(Map map) {
        return publicRefundDao.listPublicRefundCount(map);
    }

    @Override
    public PublicAndPrivateExpesetotalBo moneyTotal(Map map) {
        PublicAndPrivateExpesetotalBo publicAndPrivateExpesetotalBo =new PublicAndPrivateExpesetotalBo();
        List<PublicRefundListBO> lists = publicRefundDao.selectMoneyTotal(map);
        if (lists.size() == 0){
            publicAndPrivateExpesetotalBo.setTypePublic(new BigDecimal(0));
            publicAndPrivateExpesetotalBo.setTypePrivate(new BigDecimal(0));
            return publicAndPrivateExpesetotalBo;
        }
        //如果只返回的一个结果，并且为对公
        if (lists.size() == 1 && "0".equals(lists.get(0).getRefundType().toString())){
            publicAndPrivateExpesetotalBo.setTypePublic((BigDecimal) lists.get(0).getCost());
            publicAndPrivateExpesetotalBo.setTypePrivate(new BigDecimal(0));
            return publicAndPrivateExpesetotalBo;
        }
        //如果只返回的一个结果，并且为对私
        if (lists.size() == 1 && "1".equals(lists.get(0).getRefundType().toString())){
            publicAndPrivateExpesetotalBo.setTypePublic(new BigDecimal(0));
            publicAndPrivateExpesetotalBo.setTypePrivate((BigDecimal) lists.get(0).getCost());
            return publicAndPrivateExpesetotalBo;
        }
        //不为空
        publicAndPrivateExpesetotalBo.setTypePublic((BigDecimal) lists.get(0).getCost());
        publicAndPrivateExpesetotalBo.setTypePrivate((BigDecimal) lists.get(1).getCost());
        return publicAndPrivateExpesetotalBo;
    }

    @Override
    public Integer batchMax() {
        Integer max = publicRefundDao.batchMax();
        return max==null?100000:max+1;
    }

    @Override
    public List<PublicRefundDO> listPublicRefunds(Map map) {
        return publicRefundDao.listPublicRefunds(map);
    }
}
